home *** CD-ROM | disk | FTP | other *** search
/ Pesquisa Dirigida / Pesquisa Dirigida.iso / JOGOS / parking.swf / scripts / swingometer.as < prev   
Text File  |  2005-01-18  |  6KB  |  198 lines

  1. function Swingometer()
  2. {
  3.    this.scorehandler = new LoadVars();
  4.    this.scorehandler._parent = this;
  5.    this.prizedrawhandler = new LoadVars();
  6.    this.prizedrawhandler._parent = this;
  7.    this.menscore = new Number();
  8.    this.womenscore = new Number();
  9.    this.menscore_txt.text = "";
  10.    this.womenscore_txt.text = "";
  11.    this.errormsg = new String();
  12.    if(_global.game.finalscore < 160)
  13.    {
  14.       this.entryform_mc.gotoAndStop("nodraw");
  15.       this.submit_btn._visible = false;
  16.    }
  17.    else
  18.    {
  19.       this.entryform_mc.gotoAndStop("draw");
  20.       this.submit_btn.onRelease = function()
  21.       {
  22.          this._alpha = 50;
  23.          this.enabled = false;
  24.          this._parent.checkAndSubmit();
  25.       };
  26.    }
  27.    this.zurich_btn.onRelease = function()
  28.    {
  29.       getURL("http://ad.uk.doubleclick.net/clk;10384938;10147104;x?http://www.zurichinsurance.co.uk/parking/?score=" + _global.game.finalscore,"_blank");
  30.    };
  31.    this.retry_btn.onRelease = function()
  32.    {
  33.       _global.game.reset();
  34.    };
  35.    this.entryform_mc.tickbox_mc.selected = false;
  36.    this.entryform_mc.tickbox_mc.onRelease = function()
  37.    {
  38.       if(!this.selected)
  39.       {
  40.          this.gotoAndStop("selected");
  41.          this.selected = true;
  42.       }
  43.       else
  44.       {
  45.          this.gotoAndStop("deselected");
  46.          this.selected = false;
  47.       }
  48.    };
  49.    this.showScore();
  50.    this.sendAndGetScores();
  51. }
  52. Swingometer.prototype = new MovieClip();
  53. Swingometer.prototype.showScore = function()
  54. {
  55.    this.score_txt.text = _global.game.finalscore + " points";
  56. };
  57. Swingometer.prototype.sendAndGetScores = function()
  58. {
  59.    this.scorehandler.onLoad = function(success)
  60.    {
  61.       if(success)
  62.       {
  63.          if(this.successfulsave == "false")
  64.          {
  65.             this._parent.verbose_txt.htmlText = this.errormsg;
  66.             this._parent.debug_txt.text = this.referrer;
  67.          }
  68.          else
  69.          {
  70.             this._parent.menscore = this.men * 1;
  71.             this._parent.womenscore = this.women * 1;
  72.             this._parent.displayScores();
  73.             this._parent.calculateSwing();
  74.          }
  75.       }
  76.    };
  77.    this.scorehandler.score = _global.game.finalscore;
  78.    this.scorehandler.gender = _global.player_gender;
  79.    this.scorehandler.referrer = escape(_url);
  80.    this.scorehandler.sendAndLoad(_global.serverPath + _global.saveScoreScript,this.scorehandler,"POST");
  81. };
  82. Swingometer.prototype.displayScores = function()
  83. {
  84.    this.gotoAndStop(2);
  85.    this.menscore_txt.text = this.menscore;
  86.    this.womenscore_txt.text = this.womenscore;
  87. };
  88. Swingometer.prototype.calculateSwing = function()
  89. {
  90.    if(this.menscore == this.womenscore)
  91.    {
  92.       this.gotoAndStop(3);
  93.    }
  94.    else
  95.    {
  96.       if(this.menscore > this.womenscore)
  97.       {
  98.          var percentagemore = this.menscore / this.womenscore * 100 - 100;
  99.          if(percentagemore > 100)
  100.          {
  101.             percentagemore = 100;
  102.          }
  103.          percentagemore = Math.round(percentagemore);
  104.          var swing = percentagemore + 100;
  105.       }
  106.       else
  107.       {
  108.          var percentagemore = this.womenscore / this.menscore * 100 - 100;
  109.          if(percentagemore > 100)
  110.          {
  111.             percentagemore = 100;
  112.          }
  113.          percentagemore = Math.round(percentagemore);
  114.          var swing = percentagemore;
  115.       }
  116.       this.displaySwing(swing);
  117.    }
  118. };
  119. Swingometer.prototype.displaySwing = function(swing)
  120. {
  121.    swing <= 100 ? this.gotoAndPlay(3) : this.gotoAndPlay(101);
  122.    this.onEnterFrame = function()
  123.    {
  124.       if(this._currentframe == swing)
  125.       {
  126.          this.stop();
  127.          delete this.onEnterFrame;
  128.       }
  129.    };
  130. };
  131. Swingometer.prototype.checkAndSubmit = function()
  132. {
  133.    if(this.entryform_mc.name_txt.text != "" && this.entryform_mc.email_txt.text != "")
  134.    {
  135.       this.prizedrawhandler.name = this.entryform_mc.name_txt.text;
  136.       this.prizedrawhandler.email = this.entryform_mc.email_txt.text;
  137.       if(this.entryform_mc.tickbox_mc.selected)
  138.       {
  139.          this.prizedrawhandler.optin = "yes";
  140.       }
  141.       else
  142.       {
  143.          this.prizedrawhandler.optin = "no";
  144.       }
  145.       this.prizedrawhandler.referrer = escape(_url);
  146.       this.prizedrawhandler.onLoad = function(success)
  147.       {
  148.          if(success)
  149.          {
  150.             if(this.successfulsave == "false")
  151.             {
  152.                switch(this.errorcode * 1)
  153.                {
  154.                   case 1:
  155.                      this._parent.errormsg = "<center>Unauthorised referrer.</center>";
  156.                      this._parent.gotoAndStop("dataerror");
  157.                      break;
  158.                   case 2:
  159.                      this._parent.errormsg = "<center>That email address wasn\'t valid.<br>Please try again.</center>";
  160.                      this._parent.entryform_mc.email_txt.text = "";
  161.                      this._parent.gotoAndStop("dataerror");
  162.                }
  163.                this._parent.submit_btn._alpha = 100;
  164.                this._parent.submit_btn.enabled = true;
  165.             }
  166.             else
  167.             {
  168.                this._parent.gotoAndStop("success");
  169.             }
  170.          }
  171.          else
  172.          {
  173.             this._parent.errormsg = "<center>There was an error communicating with the server. Please email <a href=\'mailto:address@domain.com\'>address@domain.com</a> with details of this error.</center>";
  174.             this._parent.gotoAndStop("servererror");
  175.          }
  176.       };
  177.       this.prizedrawhandler.sendAndLoad(_global.serverPath + _global.prizeDrawScript,this.prizedrawhandler,"POST");
  178.    }
  179.    else
  180.    {
  181.       if(this.entryform_mc.name_txt.text == "")
  182.       {
  183.          this.errormsg = "Incomplete details...";
  184.          this.gotoAndStop("dataerror");
  185.          this.entryform_mc.name_txt.text = "Please enter your name!";
  186.       }
  187.       if(this.entryform_mc.email_txt.text == "")
  188.       {
  189.          this.errormsg = "Incomplete details...";
  190.          this.gotoAndStop("dataerror");
  191.          this.entryform_mc.email_txt.text = "Please enter your email address!";
  192.       }
  193.       this._parent.submit_btn._alpha = 100;
  194.       this._parent.submit_btn.enabled = true;
  195.    }
  196. };
  197. Object.registerClass("swingometer",Swingometer);
  198.